package org.visionlibrary.image.normalization;

import org.visionlibrary.image.model.INormalization;

public class LinearNormalization extends INormalization {
	int oldMin;

	int oldMax;

	int newMin;

	int newMax;

	float ratio;

	public LinearNormalization(int oldMin, int oldMax, int newMin, int newMax) {
		this.oldMin = oldMin;
		this.oldMax = oldMax;
		this.newMax = newMax;
		this.newMin = newMin;
		ratio = ((float) newMax - newMin) / (oldMax - oldMin);
	}

	public int normalize(int value) {
		int newValue = value;
		newValue -= oldMin;
		newValue *= ratio;
		newValue += newMin;

		return newValue;
	}
}
